textiter: fix bug in FindLogAttrFunc functions
authorSébastien Wilmet <swilmet@gnome.org>
Tue, 15 Jul 2014 15:07:14 +0000 (17:07 +0200)
committerSébastien Wilmet <swilmet@gnome.org>
Thu, 17 Jul 2014 10:56:56 +0000 (12:56 +0200)
attrs[len] is the last PangoLogAttr available, at the iter position after the
last character of the line.

For a line in the middle or the start of the buffer, the '\n' is taken
into account by 'len'. For example the is_word_end is generally reached
before the '\n', not after. But for the last line in the buffer, where
there is no trailing '\n', it is important to test until attrs[len].

The bug didn't occur before because find_by_log_attrs() worked directly
on the iter passed as the function argument. But now it is no longer the
case.

https://bugzilla.gnome.org/show_bug.cgi?id=618852

gtk/gtktextiter.c
testsuite/gtk/textiter.c

index bfc296eb86ac3561372c9959606d40d9100a8a2f..889103e53fad136f33e3aeadcd2f6a7e1824d6f3 100644 (file)
@@ -2895,7 +2895,7 @@ find_word_end_func (const PangoLogAttr *attrs,
     ++offset;
 
   /* Find end of next word */
-  while (offset < len)
+  while (offset <= len)
     {
       if (attrs[offset].is_word_end)
         {
@@ -2982,7 +2982,7 @@ find_sentence_end_func (const PangoLogAttr *attrs,
     ++offset;
 
   /* Find end of next sentence */
-  while (offset < len)
+  while (offset <= len)
     {
       if (attrs[offset].is_sentence_end)
         {
@@ -3580,7 +3580,7 @@ find_forward_cursor_pos_func (const PangoLogAttr *attrs,
   if (!already_moved_initially)
     ++offset;
 
-  while (offset < len)
+  while (offset <= len)
     {
       if (attrs[offset].is_cursor_position)
         {
index 09e3bb08bbd9c6627ce66b691655d84cd30d85b0..f3b0963443140d4a409219be5b767b76043e9ace 100644 (file)
@@ -396,7 +396,7 @@ test_word_boundaries (void)
   check_forward_word_end ("ab ", 1, 2, TRUE);
   check_forward_word_end ("ab ", 2, 2, FALSE);
   check_forward_word_end ("ab ", 3, 3, FALSE);
-  check_forward_word_end ("ab", 0, 0, FALSE); /* FIXME result_offset should be 2 */
+  check_forward_word_end ("ab", 0, 2, FALSE);
 
   check_backward_word_start (" ab", 3, 1, TRUE);
   check_backward_word_start (" ab", 2, 1, TRUE);
@@ -520,7 +520,7 @@ test_cursor_positions (void)
   check_cursor_position ("a\r\nb", TRUE, 0, 1, TRUE);
   check_cursor_position ("a\r\nb", TRUE, 1, 3, TRUE);
   check_cursor_position ("a\r\nb", TRUE, 2, 3, TRUE);
-  check_cursor_position ("a\r\nb", TRUE, 3, 3, FALSE); /* FIXME result_offset should be 4 */
+  check_cursor_position ("a\r\nb", TRUE, 3, 4, FALSE);
   check_cursor_position ("a\r\nb", TRUE, 4, 4, FALSE);
 
   /* backward */
@@ -662,7 +662,7 @@ test_sentence_boundaries (void)
   check_forward_sentence_end ("Hi. ", 2, 3, TRUE);
   check_forward_sentence_end ("Hi. ", 3, 3, FALSE);
   check_forward_sentence_end ("Hi. ", 4, 4, FALSE);
-  check_forward_sentence_end ("Hi.", 0, 0, FALSE); /* FIXME result_offset should be 3 */
+  check_forward_sentence_end ("Hi.", 0, 3, FALSE);
 
   check_backward_sentence_start (" Hi.", 4, 1, TRUE);
   check_backward_sentence_start (" Hi.", 3, 1, TRUE);